package com.rn.simple.jvm;

import java.util.HashMap;
import java.util.Map;

/**
 * Description：模拟内存泄漏样例
 *
 * @author rannuo
 * @date 2019/12/15
 */
public class CyclicDependencies {
	/**
	 * 声明缓存对象
	 */
	private static final Map<String, Object> MAP = new HashMap<>();


	public static void main(String[] args) throws InterruptedException {
		// 给打开visualvm时间
		Thread.sleep(10000);

		// 循环添加对象到缓存
		for (int i = 0; i < 1000000; i++) {
			TestMemory t = new TestMemory();
			MAP.put("key" + i, t);
		}
		System.out.println("first");

		//为dump出堆提供时间
		Thread.sleep(10000);

		for (int i = 0; i < 1000000; i++) {
			TestMemory t = new TestMemory();
			MAP.put("key" + i, t);
		}
		System.out.println("second");

		Thread.sleep(10000);

		for (int i = 0; i < 3000000; i++) {
			TestMemory t = new TestMemory();
			MAP.put("key" + i, t);
		}
		System.out.println("third");

		Thread.sleep(10000);

		for (int i = 0; i < 4000000; i++) {
			TestMemory t = new TestMemory();
			MAP.put("key" + i, t);
		}
		System.out.println("forth");

		Thread.sleep(Integer.MAX_VALUE);
		System.out.println("qqqq");
	}
}